<template>
	<view>
		<cu-custom bgColor="bg-gradual-pink" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">账号安全</block>
		</cu-custom>

		<form>
			<view class="cu-form-group">
				<view class="title">新密码：</view>
				<input placeholder="请输入新密码" v-model="password"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">确认密码：</view>
				<input placeholder="请确认密码" v-model="newpwd"></input>
			</view>
		</form>

		<view class="padding">
			<button class="cu-btn block bg-gradual-pink margin-tb-sm lg" @click="passwordSafe()">确定</button>

		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				password: '',
				newpwd: ''
			}
		},
		onLoad() {

		},
		methods: {
			// 修改密码
			passwordSafe: async function(){
				if(!this.password){
					this.$common.errorToShow('请输入新密码！');
					return;
				}
				if(!this.newpwd){
					this.$common.errorToShow('请确认新密码！');
					return;
				}
				if(this.password.length < 6){
					this.$common.errorToShow('请输入至少六位数密码！');
					return;
				}
				if(this.password != this.newpwd){
					this.$common.errorToShow('两次密码输入不正确！');
					return;
				}
				let result = await this.$api.password({
					password: this.password,
					newpwd: this.newpwd
				});
				if(result.code == 1){
					this.$common.successToShow(result.msg,()=>{
						setTimeout(() => {
							uni.hideToast();
							uni.navigateTo({
								url: '/pages/login/login'
							})
						}, 1000)
					});
					return;
				}else{
					this.$common.errorToShow(result.msg);
					return;
				}
			}
			
		},
	}
</script>

<style>
</style>
